package com.zhdl.network.duplexprotocol;

import cn.hutool.core.util.HexUtil;
import com.project.common.util.ByteHelper;
import com.project.network.server.SerialSocketServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.tio.core.intf.Packet;

import javax.annotation.Resource;
import java.util.Arrays;

@Slf4j
@Component
public class DuplexProtocolSendService {

    static SerialSocketServer serialSocketServer;

    /**
     * 初始化 Socket
     */
    public void init(SerialSocketServer server){
        serialSocketServer = server;
    }

    /**
     * 发送指令
     */
    public static void sendCmd(String hexData){
        byte[] bytes = HexUtil.decodeHex(hexData);
        serialSocketServer.write(bytes);
        log.info("待发送数据为:" + hexData + ",字节数组为:" + Arrays.toString(bytes));
    }
}
